﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using WalkingTec.Mvvm.Core;
using System.Text.Json.Serialization;
using nERP.Model;
using nERP.Model.Bas;
using nERP.Model.Po;
using nERP.Model.Wms;
using nERP.Model.Fin;

namespace nERP.Model.Po
{
    /// <summary>
    /// 采购订单
    /// </summary>
	[Table("Buy")]
    [SoftKey(nameof(Buy.BuyCode))]
    [Display(Name = "_Model.Buy")]
    public class Buy : BasePoco, IPersistPoco, ITenant, IWorkflow
    {
        [Display(Name = "_Model._Buy._BuyCode")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("采购单号")]
        [Required(ErrorMessage = "Validate.{0}required")]
        [CanNotEdit]
        public string BuyCode { get; set; }
        [Display(Name = "_Model._Buy._Supplier")]
        [Comment("供应商")]
        [NotMapped]
        public Supplier Supplier { get; set; }
        [Display(Name = "_Model._Buy._Supplier")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Required(ErrorMessage = "Validate.{0}required")]
        [Comment("供应商")]
        public string SupplierId { get; set; }
        [Display(Name = "_Model._Buy._SettlementAccount")]
        [Comment("结算账户")]
        [NotMapped]
        public SettlementAccount SettlementAccount { get; set; }
        [Display(Name = "_Model._Buy._SettlementAccount")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("结算账户")]
        public string SettlementAccountId { get; set; }
        [Display(Name = "_Model._Buy._InvoicesDate")]
        [Comment("单据日期")]
        public DateTime? InvoicesDate { get; set; }
        [Display(Name = "_Model._Buy._MakeUser")]
        [Comment("制单人")]
        [NotMapped]
        public FrameworkUser MakeUser { get; set; }
        [Display(Name = "_Model._Buy._MakeUser")]
        [StringLength(32, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("制单人")]
        public string MakeUserId { get; set; }
        [Display(Name = "_Model._Buy._DeliveryDate")]
        [Comment("交货日期")]
        public DateTime? DeliveryDate { get; set; }
        [Display(Name = "_Model._Buy._InvoicesImage")]
        [Comment("单据附件")]
        public List<BuyInvoicesImage> InvoicesImage { get; set; }
        [Display(Name = "_Model._Buy._Status")]
        [Comment("单据状态")]
        public StatusTypeEnum? Status { get; set; }
        [Display(Name = "_Model._Buy._TotalPrice")]
        [Comment("总金额")]
        public decimal? TotalPrice { get; set; }
        [Display(Name = "_Model._Buy._TotalPrice1")]
        [Comment("已结金额")]
        public decimal? TotalPrice1 { get; set; }
        [Display(Name = "_Model._Buy._TotalPrice2")]
        [Comment("未结金额")]
        public decimal? TotalPrice2 { get; set; }
        [Display(Name = "_Model._Buy._Remark")]
        [StringLength(256, ErrorMessage = "Validate.{0}stringmax{1}")]
        [Comment("备注")]
        public string Remark { get; set; }
        [Display(Name = "_Model._BuyDetail._Buy")]
        [InverseProperty("Buy")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Po.BuyDetail.BuyId))]
        public List<BuyDetail> BuyDetail_Buy { get; set; }
        [Display(Name = "_Model._BuyReturn._Buy")]
        [InverseProperty("Buy")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Po.BuyReturn.BuyId))]
        public List<BuyReturn> BuyReturn_Buy { get; set; }
        [Display(Name = "_Model._BuyReturnDetail._Buy")]
        [InverseProperty("Buy")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Po.BuyReturnDetail.BuyId))]
        public List<BuyReturnDetail> BuyReturnDetail_Buy { get; set; }
        [Display(Name = "_Model._BuyInWarehouse._Buy")]
        [InverseProperty("Buy")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Wms.BuyInWarehouse.BuyId))]
        public List<BuyInWarehouse> BuyInWarehouse_Buy { get; set; }
        [Display(Name = "_Model._BuyInWarehouseDetail._Buy")]
        [InverseProperty("Buy")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Wms.BuyInWarehouseDetail.BuyId))]
        public List<BuyInWarehouseDetail> BuyInWarehouseDetail_Buy { get; set; }
        [Display(Name = "_Model._BuyReturnOutWarehouse._Buy")]
        [InverseProperty("Buy")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Wms.BuyReturnOutWarehouse.BuyId))]
        public List<BuyReturnOutWarehouse> BuyReturnOutWarehouse_Buy { get; set; }
        [Display(Name = "_Model._BuyReturnOutWarehouseDetail._Buy")]
        [InverseProperty("Buy")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Wms.BuyReturnOutWarehouseDetail.BuyId))]
        public List<BuyReturnOutWarehouseDetail> BuyReturnOutWarehouseDetail_Buy { get; set; }
        [Display(Name = "_Model._PaymentDetail._Buy")]
        [InverseProperty("Buy")]
        [NotMapped]
        [SoftFK(nameof(nERP.Model.Fin.PaymentDetail.BuyId))]
        public List<PaymentDetail> PaymentDetail_Buy { get; set; }
        [Display(Name = "_Model._Buy._IsValid")]
        [Comment("是否有效")]
        [Required(ErrorMessage = "Validate.{0}required")]
        public bool IsValid { get; set; } = true;
        [StringLength(50, ErrorMessage = "Validate.{0}stringmax{1}")]
        public string TenantCode { get; set; }

    }
    public class BuyInvoicesImage : TopBasePoco, ISubFile
    {
        public Guid BuyId { get; set; }
        public Buy Buy { get; set; }
        public Guid FileId { get; set; }
        public FileAttachment File { get; set; }
        public int Order { get; set; }
    }

}
